import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;


public class ThreadPool {
    private static final int CORE_POOL_SIZE = 20;
    private static final int MAX_POOL_SIZE = 40;
    private static final int KEEP_ALIVE_TIME = 10000;
    private static final TimeUnit TIME_UNIT = TimeUnit.SECONDS;
    private static final int BLOCKING_QUEUE_SIZE = 100;
    
    
    public static ThreadPoolExecutor threadPool = new ThreadPoolExecutor(
            CORE_POOL_SIZE, MAX_POOL_SIZE, KEEP_ALIVE_TIME, TIME_UNIT,
            new ArrayBlockingQueue<Runnable>(BLOCKING_QUEUE_SIZE));
    
    private ThreadPool() {}

    private static class Loader {

        private static final ThreadPool INSTANCE = new ThreadPool();
    }

    public static ThreadPool getInstance() {
        return Loader.INSTANCE;
    }
    
    public static void add(Runnable r) {
        threadPool.execute(r);
    }

}
